﻿using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Controls;
using FxWinSuper.Annotations;
using System.Windows;
using FxWinSuper.Util;

namespace FxWinSuper.UI.Menu.Controls
{
	/// <summary>
	/// DownloadView.xaml 的交互逻辑
	/// </summary>
	public partial class DownloadView : UserControl, INotifyPropertyChanged
	{
		public DownloadView()
		{
			InitializeComponent();
		}

		public event PropertyChangedEventHandler PropertyChanged;

		[NotifyPropertyChangedInvocator]
		protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
		{
			PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
		}

		private string _title;

		public string Title
		{
			get => _title;
			set
			{
				_title = value;
				OnPropertyChanged();
			}
		}

		private int _value;

		public int Value
		{
			get => _value;
			set
			{
				_value = value;
				OnPropertyChanged();
			}
		}

		private bool _needConfirm;

		public bool NeedConfirm
		{
			get => _needConfirm;
			set
			{
				_needConfirm = value;
				OnPropertyChanged();
			}
		}

		public static CommPropConvert BoolToVisibleConvert => new CommPropConvert(obj => (bool)obj ? Visibility.Visible: Visibility.Collapsed);

		/// <summary>
		/// 用户点击确认事件
		/// </summary>
		public event RoutedEventHandler OnConfirmEvent;

		/// <summary>
		/// 用户点击cancel
		/// </summary>
		public event RoutedEventHandler OnCancelEvent;

		private void OnClickConfirm(object sender, RoutedEventArgs e)
		{
			NeedConfirm = false;
			OnConfirmEvent?.Invoke(sender, e);
		}
		private void OnClickCancel(object sender, RoutedEventArgs e)
		{
			OnCancelEvent?.Invoke(sender, e);
		}
	}
}
